package com.zyk.leetcode;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author zhangsan
 * @date 2021/4/9 10:38
 */
public class M0302 {

    static class MinStack {
        // 存放内容
        Deque<Integer> stack1;
        // 存放最小元素
        Deque<Integer> stack2;

        // addLast, popFirst

        /**
         * initialize your data structure here.
         */
        public MinStack() {
            stack1 = new ArrayDeque<>();
            stack2 = new ArrayDeque<>();
        }

        public void push(int x) {
            stack1.push(x);
            if (stack2.isEmpty()) {
                stack2.push(x);
            } else {
                stack2.push((stack2.peekFirst() < x ? stack2.peekFirst() : x));
            }
        }

        public void pop() {
            stack1.pollFirst();
            stack2.pollFirst();
        }

        public int top() {
            return stack1.peekFirst();
        }

        public int getMin() {
            return stack2.peekFirst();
        }
    }

}
